<?php
namespace app\common\model;
use x\Xbase;
    
#零售奖
class Awardlingshou extends Xbase
{  
    /**
	 * 零售奖
	 * @param  [type] $order_data [user_vip]
	 * @param  [type] $order_id   [user_vip_id]
	 * @param  [type] $level      [升级级别]
	 * @return [type]             [description]
	 */
    public function doit($order_data,$order_id,$level=1){
    	exit('废弃');
    	#零售
    	if ($order_data['lingshou_money']) {
    		$money = $order_data['lingshou_money'];
    		$fee = 0;
	        $real_money = bcsub($money,$fee,2);
	    	$mysql = [];
	    	$data = [
	    		'order_no' => $this->com_order_no(),
	            'user_vip_id' => $order_id,
	    		'user_id' => $order_data['lingshou_user_id'],
	    		'level' => 2,
	            'money' => $money,
	            'fee' => $fee,
	            'status' => 1,
	            'note' => '获得零售奖',
	            'real_money' => $real_money,
	    		'create_time' => time(),
	    	];
	        $mysql[] = $id = $this->db->insert('award_lingshou',$data);

	        $mysql[] = m('Userbill','xcom')->doit($data['order_no'],$data['user_id'],104,'award_lingshou',$id,$data['real_money'],'money_sy','获得零售奖');
    	}
    	#批发
    	if ($order_data['pifa_money']) {
    		$money = $order_data['pifa_money'];
    		$fee = 0;
	        $real_money = bcsub($money,$fee,2);
	    	$mysql = [];
	    	$data = [
	    		'order_no' => $this->com_order_no(),
	            'user_vip_id' => $order_id,
	    		'user_id' => $order_data['pifa_user_id'],
	    		'level' => 3,
	            'money' => $money,
	            'fee' => $fee,
	            'status' => 1,
	            'note' => '获得零售奖',
	            'real_money' => $real_money,
	    		'create_time' => time(),
	    	];
	        $mysql[] = $id = $this->db->insert('award_lingshou',$data);

	        $mysql[] = m('Userbill','xcom')->doit($data['order_no'],$data['user_id'],104,'award_lingshou',$id,$data['real_money'],'money_sy','获得零售奖');
    	}
    	#代理
    	if ($order_data['daili_money']) {
    		$money = $order_data['daili_money'];
    		$fee = 0;
	        $real_money = bcsub($money,$fee,2);
	    	$mysql = [];
	    	$data = [
	    		'order_no' => $this->com_order_no(),
	            'user_vip_id' => $order_id,
	    		'user_id' => $order_data['daili_user_id'],
	    		'level' => 4,
	            'money' => $money,
	            'fee' => $fee,
	            'status' => 1,
	            'note' => '获得零售奖',
	            'real_money' => $real_money,
	    		'create_time' => time(),
	    	];
	        $mysql[] = $id = $this->db->insert('award_lingshou',$data);

	        $mysql[] = m('Userbill','xcom')->doit($data['order_no'],$data['user_id'],104,'award_lingshou',$id,$data['real_money'],'money_sy','获得零售奖');
    	}
        foreach($mysql as $v){if(!$v) return false;}return true;
    }
}
